package hot_problems_100;

public class P15_0238 {
    public int[] productExceptSelf(int[] nums) {
        int[] pre_sum = new int[nums.length];
        int[] after_sum = new int[nums.length];

        pre_sum[0] = 1;
        after_sum[nums.length-1] = 1;
        for(int i=1; i<nums.length; i++){
            pre_sum[i] = pre_sum[i-1] * nums[i-1];
            after_sum[nums.length-i-1] = after_sum[nums.length-i] * nums[nums.length-i];
        }
        for(int i=0; i<nums.length; i++){
            pre_sum[i] = pre_sum[i] * after_sum[i];
        }
        return pre_sum;
    }
}
